﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CKEditorConfig.ashx.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the CKEditorConfig class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace LidocaineWeb
{
    using System.Collections.Generic;
    using System.Web;
    using Lidocaine;

    /// <summary>
    /// Defines the CKEditorConfig class.
    /// </summary>
    public class CKEditorConfig : IHttpHandler
    {
        /// <summary>
        /// Gets a value indicating whether or not the handler is reusable.
        /// </summary>
        public bool IsReusable
        {
            get { return false; }
        }

        /// <summary>
        /// This is part of the standard implementation of the IHttpHandler interface.
        /// </summary>
        /// <param name="context">The HTTP context associated with the call to the handler.</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/javascript";
            Profile currentUser = Profile.Current;
            IList<string> roles = currentUser.Roles;
            if (roles.Contains("Site Administrator"))
            {
                context.Response.Write(
    @"
    CKEDITOR.editorConfig = function( config ) {
        config.toolbar = [
            ['Source'],
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker'],
            ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
            '/',
            ['Templates', 'Styles', 'Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            '/',
            ['Link', 'Unlink', 'Anchor'],
            ['Image', 'Flash', 'Module Placeholder', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
            ['Maximize']
        ];
        config.filebrowserBrowseUrl = '/cms/filebrowser.htm';
        config.filebrowserWindowWidth = 668;
        config.filebrowserWindowHeight = 610;
        config.contentsCss = '/includes/contents.css'; // Upload your custom CSS to a Lidocaine directory.
        config.height = 350;
        config.enterMode = CKEDITOR.ENTER_BR;
        config.stylesSet = [
        { name: 'Content Heading', element: 'h3' },
        { name: 'Content Sub-Heading', element: 'h4' }
        ];
        config.extraPlugins = 'ajax,moduleplaceholder';
    };");
            }
            else
            {
                context.Response.Write(
    @"
    CKEDITOR.editorConfig = function( config ) {
        config.toolbar = [
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker'],
            ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
            '/',
            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            '/',
            ['Link', 'Unlink', 'Anchor'],
            ['Image', 'Flash', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
            ['Maximize']
        ];
        config.contentsCss = '/includes/contents.css'; // Upload your custom CSS to a Lidocaine directory.
        config.height = 350;
        config.enterMode = CKEDITOR.ENTER_BR;
    };");
            }
        }
    }
}